<script type="text/javascript" >
var menu =
[

//These need to be modified so that it scrolls to the proper place on the page,
{"name": "Clients", "href": "?page=clients", "file": "clients",
   <?php if (isset($_SESSION['ClientID']) ) { ?>
   "submenu": [ {"name": "Invoices", "href": "?a=clients&page=invoices"},
		      {"name": "Upload files", "href": "?a=clients&page=upload"},
		      {"name": "Download files", "href": "?a=clients&page=downloadable_Files"},
		      {"name": "Bandwidth",   "href": "?a=clients&page=bandwidth"},
		      {"name": "Drive Space",   "href": "?a=clients&page=drivespace"} ] 
   <?php } 
   ?> },

   {"name": "Contact", "href": "?page=contact", "file": "contact", 
      "submenu": [ {"name":"Email", "href": "?page=contact"},
		         {"name":"Telephone", "href": "?page=contact"},
		         {"name":"Postal", "href": "?page=contact"},
                   {"name":"Map", "href": "?page=contact"} ] },

   {"name": "Portfolio", "href": "?page=portfolio", "file": "portfolio",
      "submenu": [ {"name":"Desktop Application", "href": "?page=portfolio"},
		         {"name":"Web Development", "href": "?page=portfolio"},
		         {"name":"PDA Applications", "href": "?page=portfolio"}, ] },

   {"name": "Profile", "href": "?page=profile", "file": "profile",
      "submenu": [ {"name":"History", "href": "?page=profile"} ] },

   {"name": "Services", "href": "?page=services", "file": "services",
      "submenu": [ {"name":"Desktop Application", "href": "?page=services"},
		         {"name":"PDA Applications", "href": "?page=services"},
		         {"name":"Web Developement", "href": "?page=services"},
		         {"name":"Graphic Design", "href": "?page=services"},
		         {"name":"Web Hosting", "href": "?page=services"} ] },

   {"name": "Web Hosting", "href": "?page=webhosting", "file": "webhosting",
      "submenu": [ {"name":"Host Accounts", "href": "?page=webhosting"}, 
		         {"name":"Services", "href": "?section=webhosting&amp;page=webservice"},
		         {"name":"References", "href": "?section=webhosting&amp;page=webref"},
		         {"name":"How-to", "href": "?section=webhosting&amp;page=webhow-to"} ] },

   <?php if (isset($_SESSION['group']) && substr_count($_SESSION['group'],"Admin") == 1) { ?>
   {"name": "Tools",   "href": "?section=admin&page=AccountManTools",   "file": "AccountManTools",
      "submenu": [ {"name":"phpMyAdmin", "href": "?a=AccountManTools&section=special&page=downformaintenance"},
		   {"name":"Qmail Admin", "href": "?a=AccountManTools&iframe=https://admin.jppeach.net/qmail/qmailadmin"}, 
     	           {"name":"Virtual Domain Administrator", "href": "?a=AccountManTools&section=special&page=downformaintenance"}, ] },
   
   {"name":"Wiki",   "href": "?section=admin&page=wiki",   "file": "wiki",
      "submenu": [ {"name":"Wiki Main Page", "href": "?a=wiki&section=special&page=downformaintenance"}, ] },

   <?php }
	if (isset($_SESSION['group']) && (substr_count($_SESSION['group'],"Admin") == 1 ||  substr_count($_SESSION['group'],"Concordia") == 1 )) { ?>

   {"name":"Speak Easy",   "href": "?section=admin&page=speakEasy",   "file": "speakEasy",
      "submenu": [ {"name":"Speak Easy Managed Services", "href": "?a=speakEasy&iframe=http://www.speakeasy.net/service/ms/"},
                   {"name":"Speak Easy Management",   "href": "?a=speakEasy&iframe=https://www.speakeasy.net/myspeak/index.mpl"},
                   {"name":"Support",   "href": "?a=speakEasy&iframe=http://support.netfire.com/"}, ] },

   <?php }
	if (isset($_SESSION['group']) && (substr_count($_SESSION['group'],"Admin") == 1 || substr_count($_SESSION['group'],"Concordia") == 1 || substr_count($_SESSION['group'],"Users")    == 1)) { ?>
   {"name":"Mail",   "href": "?section=admin&page=Mail",   "file": "Mail",
      "submenu": [ {"name":"Horde", "href": "?a=Mail&iframe=http://webmail.jppeach.net/horde/login.php"},
		         {"name":"SquirrelMail",   "href": "?a=Mail&section=special&page=downformaintenance"},
		         {"name":"RoundCube WebMail", "href": "?a=Mail&iframe=http://roundcube.jppeach.net/"},

   <?php
	if (isset($_SESSION['group']) && (substr_count($_SESSION['group'],"Admin") == 1 || substr_count($_SESSION['group'],"Concordia") == 1 )) { ?>
		
   {"name":"Qmail Admin",	"href": "?a=Mail&section=special&page=downformaintenance"},
   {"name":"Qmail Domain Administrator", "href": "?a=Mail&section=special&page=downformaintenance"},
   {"name":"Qmail Mrtg Stats", "href": "?a=Mail&section=special&page=downformaintenance"},

   <?php } ?>
	]
	},

   <?php }
	if (isset($_SESSION['group']) && ( substr_count($_SESSION['group'],"Admin") == 1 || substr_count($_SESSION['group'],"Concordia") == 1)) { ?>

   {"name":"System Info",   "href": "?section=admin&page=SystemInfo",   "file": "SystemInfo",
	"submenu": [ {"name":"Domain Bandwidth",   "href": "?a=SystemInfo&section=special&page=downformaintenance"},
		        {"name":"Server Bandwidth graphs",   "href": "?a=SystemInfo&section=special&page=downformaintenance"},
		        {"name":"Enviroment Variables",	"href": "?a=SystemInfo&section=special&page=downformaintenance"},
     	        {"name":"Isoqlog MTA Log Analyzer", "href": "?a=SystemInfo&section=special&page=downformaintenance"},
		        {"name":"phpInfo",   "href": "?a=SystemInfo&section=special&page=downformaintenance"},
		        {"name":"Qmail Mrtg Stats",   "href": "?a=SystemInfo&section=special&page=downformaintenance"},
		        {"name":"SysWatch",   "href": "?a=SystemInfo&section=special&page=downformaintenance"},
		        {"name":"Webalizer - jppeach.com",   "href": "?a=SystemInfo&section=special&page=downformaintenance"},
		        {"name":"Apache Info",  "href": "?a=SystemInfo&iframe=https://admin.jppeach.net/apache/server-info/"},
		        {"name":"Apache Status",  "href": "?a=SystemInfo&iframe=https://admin.jppeach.net/apache/server-status/"}, ] },
   
   {"name":"Misc",   "href": "?section=admin&page=Misc",   "file": "Misc",
	"submenu": [ {"name":"DynDNS", "href": "?a=Misc&iframe=https://www.dyndns.com/account/services/hosts/jpbackup.homeip.net"},
		        {"name":"EveryDNS", "href": "?a=Misc&iframe=http://www.everydns.com/index.php"}, ] },

   {"name":"Contact Info",   "href": "?section=admin&page=ContactInfo",   "file": "ContactInfo",
	"submenu": [], },

   <?php } ?> ]

window.onload = function() {

	//This block determines which page the user is currently on
	var querry = window.location.search;
	var equalSign = querry.indexOf("=");
//<![CDATA[
	if (equalSign == -1) { var page = "services"; }
	else {
		var ampersand = querry.indexOf("&");
		if (ampersand > 0) { var page = querry.substring(equalSign + 1, ampersand); }
		else { var page = querry.substr(equalSign + 1); }
		}
//]]>
	if (page == "admin") {
		var equalSign = querry.lastIndexOf("=");
		page = querry.substr(equalSign + 1); }



	var sidebar = document.createElement("div");
	sidebar.id = "Sidebar";
	document.body.appendChild(sidebar);

	var sideLinkList = document.createElement("ul");
	sideLinkList.id = "ul2"

	// MENU GENERATION CODE HERE
//<![CDATA[
	for (var i = 0; i < menu.length; ++i) {
//]]>
		var sideLink = document.createElement("li");

	    //li.setAttribute('class',"SideLink");
	    var newAttr = document.createAttribute("class");
		newAttr.nodeValue = "SideLink";
		sideLink.setAttributeNode(newAttr);

		var sideLinkElement = document.createElement("a");

		if (page == menu[i].file) {
			var sideLinkImage = document.createElement("img");
			sideLinkImage.setAttribute('src',"../images/arrowD.jpg");
			sideLinkImage.setAttribute('class',"downArrow");
			sideLinkElement.appendChild(sideLinkImage);
		}
		else {
			var sideLinkImage = document.createElement("img");
			sideLinkImage.setAttribute('src',"../images/arrowR.jpg");
			sideLinkImage.setAttribute('class',"sidelinkimage");
			sideLinkElement.appendChild(sideLinkImage);
		}

		var sideLinkName = document.createTextNode(menu[i].name)
		sideLinkElement.href = menu[i].href;
		sideLinkElement.name = menu[i].name;

		sideLinkElement.appendChild(sideLinkName);
		sideLink.appendChild(sideLinkElement);

		// SUBMENU GOES HERE
//<![CDATA[
		if (menu[i].submenu && page == menu[i].file) {
//]]>
			var subLinkList = document.createElement('ul');
			// subLinkList.setAttribute("class","SubLink");

			var submenu = menu[i].submenu;
//<![CDATA[
			for (var j = 0; j < submenu.length; ++j) {
//]]>

				var subLink = document.createElement("li");

				var newAttr = document.createAttribute("class");
				newAttr.nodeValue = "SubLink";
				subLink.setAttributeNode(newAttr);

				var subLinkElement = document.createElement("a");

				// adding the sub_link.gif to the subLink
				var subLinkImage = document.createElement("img");
				subLinkImage.setAttribute('src',"../images/nav/sub_link.gif");
				subLinkImage.setAttribute('class',"sublinkimage");
				subLinkElement.appendChild(subLinkImage);

				var subLinkName = document.createTextNode(submenu[j].name)
				subLinkElement.href = submenu[j].href;
				subLinkElement.appendChild(subLinkName);

				subLink.appendChild(subLinkElement);
				subLinkList.appendChild(subLink);
			}

			// adding extra space below sublinks
			var subLinkBreak = document.createElement("li");
			var brk = document.createElement("br");
			subLinkBreak.appendChild(brk);
			var AttrSub = document.createAttribute("class");
			AttrSub.nodeValue = "SubLink";
			subLinkBreak.setAttributeNode(AttrSub);
			subLinkList.appendChild(subLinkBreak);

			sideLink.appendChild(subLinkList);
		}

		sideLinkList.appendChild(sideLink);
	}


	sidebar.appendChild(sideLinkList);


}

</script>

